<template>
  <div>
    <div class="select">
      <!-- <p>监测站</p> -->
      <el-select v-show="false" v-model="name" placeholder="请选择">
        <el-option
          v-for="item in options"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        >
        </el-option>
      </el-select>
      <p style="margin-left: 40px">日期区间</p>
      <el-date-picker
        v-model="date"
        type="daterange"
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
      >
      </el-date-picker>
      <el-button plain class="btn" @click="select()">查询</el-button>
    </div>
    <!-- 表格 -->
    <el-table
      v-loading="loading"
      :data="data.slice((currentPage - 1) * pageSize, currentPage * pageSize)"
      style="width: 100%"
    >
      <el-table-column prop="fields.0" label="index" width="180">
      </el-table-column>
      <el-table-column prop="fields.1" label="Unnamed: 0" width="180">
      </el-table-column>
      <el-table-column prop="fields.2" label="times"> </el-table-column>
      <el-table-column prop="fields.3" label="temperature"> </el-table-column>
      <el-table-column prop="fields.4" label="humidity"> </el-table-column>
      <el-table-column prop="fields.5" label="winddirection"> </el-table-column>
      <el-table-column prop="fields.6" label="windpower"> </el-table-column>
      <el-table-column prop="fields.7" label="rains"> </el-table-column>
      <el-table-column prop="fields.8" label="rains7041JA23"> </el-table-column>
      <el-table-column prop="fields.9" label="waterlevels7041JA23">
      </el-table-column>
      <el-table-column prop="fields.10" label="rains7041JA24">
      </el-table-column>
      <el-table-column prop="fields.11" label="waterlevels7041JA24">
      </el-table-column>
      <el-table-column prop="fields.12" label="waterlevels"> </el-table-column>
    </el-table>
    <!-- 分页器 -->
    <div class="block" style="margin-top: 15px">
      <el-pagination
        align="center"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[15, 100]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="data.length"
      >
      </el-pagination>
    </div>
  </div>
</template>
 
  <script>
import { postKeyValueRequest } from "../utils/api";
import axios from 'axios'
export default {
  name: "HistoricalPage",
  data() {
    return {
      data: [],
      currentPage: 1, // 当前页码
      total: 10000, // 总条数
      pageSize: 15, // 每页的数据条数
      loading: true,
      options: [
        {
          value: "选项1",
          label: "黄金糕",
        },
      ],
      name: "",
      date: "",
    };
  },
  methods: {
    //每页条数改变时触发 选择一页显示多少行
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.currentPage = 1;
      this.pageSize = val;
    },
    //当前页改变时触发 跳转其他页
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.currentPage = val;
    },
    select() {
      axios
        .post("/selectDataByNameAndDate", {
          name: this.name,
          date: this.date,
        })
        .then( (res) =>{
          this.data = res
          console.log(this.data)
          this.total = res.length
        })
    },
  },
  mounted() {
    postKeyValueRequest("/dataTest").then((resp) => {
      this.data = resp;
      this.total = resp.length;
      this.loading = false;
    });
  },
};
</script>
<style scoped>
.select {
  display: flex;
  justify-content: center;
}
.select p {
  font-size: 17px;
  line-height: 10px;
  margin-right: 20px;
}
.select .btn {
  margin-left: 20px;
  height: 40px;
}
</style>